#ifndef ADMPIPE_H
#define ADMPIPE_H

#include "npipe.h"

class AdminProtocol;

enum AdminPipeErrors	/*APE*/
{
	APE_UNKNOWN_REQUEST,
	APE_MEMORY_ERROR,
	APE_ATTEMPT_RELOGIN,
	APE_LIST_NO_MORE,
	APE_UNKNOWN_PACKAGE,
	APE_INVALID_UPDATE,
	APE_INVALID_ADD,
	APE_INVALID_REMOVE
};

class AdminPipe : public NamedPipe
{
	public:
		AdminPipe();
		~AdminPipe();

		bool8 create();
		bool8 initOk();

		void msgStart();
		void msgAdd(uint8 Byte);
		void msgAdd(uint8* buf, int32 len);
		void msgAdd(const String& str, bool8 unicode=false);
		bool8 msgEnd();
		uint8* msgGetBuf();
		void msgReleaseBuf(int32 Amt);
		void msgStartUserBuilt();
		void msgEndUserBuilt();
		uint32 msgGetRemain();

		void sendError(int32);

		bool8 isLoggedOn();
		void setLoggedOn();

	protected:
		void connectionReset();
		int32 determineProtocol(uint8);
		bool8 getResponse();

	private:
		void* initSecurity();
		void destroySecurity(void*);

	protected:
		int32 loggedOn;
		int32 msglen;

		enum Protocols
		{
			LOGIN, LIST, ADD, REMOVE, UPDATE,
			NUMPROTOCOLS
		};
		AdminProtocol*	protocol[NUMPROTOCOLS];
};

inline bool8
AdminPipe::isLoggedOn()
{
	return (bool8)(loggedOn != 0);
}

inline void
AdminPipe::setLoggedOn()
{
	loggedOn = true;
}


#endif
